import 'package:get/get.dart';
import 'package:sweetim/model/member_info.dart';

import '../main.dart';

class MemberService extends GetxService {

  get checkToken => storage.hasData("token");

  get token => storage.read("token");

  MemberInfo getInfo() {
    var info = storage.read("info");
    if(info is Map) {
      return MemberInfo.fromJson(info);
    }
    return info;
  }

  putInfo(MemberInfo memberInfo) async {
    await storage.write("token", memberInfo.token);
    await storage.write("info", memberInfo);
    await storage.write("id", memberInfo.m!.id!);
  }

  get id => storage.read("id");

  Future<void> clean() async  {
    await storage.remove("token");
    await storage.remove("info");
    await storage.remove("id");
  }
}
